package com.sitanyun.merchant.guide.frament;


import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.google.gson.Gson;
import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.adapter.TabAdapter;
import com.sitanyun.merchant.guide.base.BaseFragment;
import com.sitanyun.merchant.guide.bean.ScenMyMerchantBean;
import com.sitanyun.merchant.guide.callback.StringCallbacks;
import com.sitanyun.merchant.guide.url.Urls;
import com.sitanyun.merchant.guide.view.fragment.AllmessagesFragment;
import com.sitanyun.merchant.guide.view.fragment.ProcessedFragment;
import com.sitanyun.merchant.guide.view.fragment.UntreatedFragment;
import com.sitanyun.merchant.guide.weiht.SharedPreferenceUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import okhttp3.Call;

/**
 * A simple {@link Fragment} subclass.
 * 消息列表
 */
public class ScenMyFragment extends BaseFragment {

    @BindView(R.id.tv_return)
    ImageView tvReturn;
    @BindView(R.id.tv_title_str)
    TextView tvTitleStr;
    @BindView(R.id.image_right_key)
    ImageView imageRightKey;
    @BindView(R.id.tv_right_key)
    TextView tvRightKey;
    @BindView(R.id.ff_main_layout)
    FrameLayout ffMainLayout;
    @BindView(R.id.tab_view)
    SlidingTabLayout tabView;
    @BindView(R.id.vp_view)
    ViewPager vpView;
    private static final String[] mTitle = {"未处理", "已处理","全部消息"};
    private static final BaseFragment[] size = new BaseFragment[]{new UntreatedFragment(), new ProcessedFragment(),new AllmessagesFragment()};

    @Override
    public int getLayoutId() {
        return R.layout.fragment_scen_my;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        tvTitleStr.setText("消息列表");
        tvReturn.setVisibility(View.GONE);
        vpView.setAdapter(new TabAdapter(getActivity(), getChildFragmentManager(), mTitle, size));
        tabView.setViewPager(vpView);
    }

    @Override
    public void initView() {
        OkHttpUtils.get().url(Urls.getMerchantInfo)
                .addHeader("Content-Type", "application/json")
                .addHeader("Authorization", "Bearer " + SharedPreferenceUtil.getStringData("token"))
                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                ScenMyMerchantBean  scenMyMerchantBean = new Gson().fromJson(response, ScenMyMerchantBean.class);
                if (scenMyMerchantBean.getCode()==0){
                    SharedPreferenceUtil.SaveData("merchant",scenMyMerchantBean.getData().getNodeName()+"");
                    SharedPreferenceUtil.SaveData("merchantid",scenMyMerchantBean.getData().getEnterpriseId()+"");
                }
            }
        });
    }
}
